package com.dotflat.satistics.vo.healthy;

import com.matt.foundation.utils.MapConvertUtil;
import lombok.Data;

import java.util.Map;


/**
 * *******************************
 * Created by Tim.
 * form com.matt
 * on 2018/7/3
 * *******************************
 */
@Data
public class StatUnitPriceVo {

    private String timeName;

    private Double totalAmount = 0.0;

    private Double totalCount = 0.0;

    private Double unitPrice;

    public static StatUnitPriceVo of(Map map) {
//        StatUnitPriceVo stat = new StatUnitPriceVo();
//        stat.setTimeName(map.get("timeName").toString());
//        stat.setTotalAmount(map.get("totalAmount") == null ? 0 : Double.valueOf(map.get("totalAmount").toString()));
//        stat.setTotalCount(map.get("totalCount") == null ? 0 :Double.valueOf(map.get("totalCount").toString()));
//        stat.setUnitPrice(map.get("unitPrice") == null ? 0 :Double.valueOf(map.get("unitPrice").toString()));

        StatUnitPriceVo stat = MapConvertUtil.mapToObject(map, StatUnitPriceVo.class);

        if(stat.unitPrice == 0 && stat.totalAmount != 0 && stat.totalCount > 0){
            stat.unitPrice = stat.totalAmount / stat.totalCount;
        }

        return stat;
    }
}
